//
//  SYJEmoticonPageView.swift
//  weibo
//
//  Created by 孙英建 on 16/4/25.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

// cell 可重用标示符
private let EmoticonPageViewCellId = "EmoticonPageViewCellId"

class SYJEmoticonPageView: UICollectionView {


    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 设置控件
    func setupUI(){
        
        registerClass(SYJEmoticonPageViewCell.self, forCellWithReuseIdentifier: EmoticonPageViewCellId)
        
        dataSource = self
        
        // 布局
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: kWidth, height: 216 - 37)
        
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = .Horizontal
        
    }
}

// MARK: - 数据源方法
extension SYJEmoticonPageView: UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return SYJEmoticonTools.sharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return SYJEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(EmoticonPageViewCellId, forIndexPath: indexPath) as! SYJEmoticonPageViewCell
        
        cell.indexPath = indexPath
        cell.emoticonArr = SYJEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        return cell
    }
}










